#!/usr/bin/python

"""
 Module: maingui.py
  Ver: 2.2; (original version) Rev Last: 11/02/2012 - Previous: 10/03/2012

 Rev 2.2.1; Last: 02/12/2013 - Previous: 02/11/2013  (AEM)
   - Clean up to match PEP8 style guide as closely as practical
   - Clean up to match pylint style guide as closely as practical
   - Add save button on main gui, functions same as menu save action

  Set and control song info panel and file info panel gui components
  in the showtags main panels.

"""

import wx
import os


def init_sizers(myself):
   myself.vbox0 = wx.BoxSizer(wx.VERTICAL)

   myself.FileListPanel = wx.Panel(myself, wx.ID_ANY, style=wx.SUNKEN_BORDER)
   myself.SongInfoPanel = wx.Panel(myself, wx.ID_ANY, style=wx.SUNKEN_BORDER)
   myself.FileInfoPanel = wx.Panel(myself, wx.ID_ANY, style=wx.SUNKEN_BORDER)

   myself.PicturePanel = wx.Panel(myself.SongInfoPanel, wx.ID_ANY,
                                  pos=(35, 75),
                                  size=(190, 190), style=wx.BORDER_RAISED)
   myself.PicturePanel.SetBackgroundColour("#F0F0F0")

   myself.FileListPanel.SetBackgroundColour("#B0E2FF")
   myself.SongInfoPanel.SetBackgroundColour("#F5F5F5")
   myself.FileInfoPanel.SetBackgroundColour('#F5F5F5')

   #*** Create the listctrl component that will hold the meta data
   #    for multiple mp3 files
   #myself.InitListCtrl()
   #mycnt = myself.SongListCtrl.GetColumnCount()

   myself.vbox = wx.BoxSizer(wx.VERTICAL)
   myself.vbox.Add(myself.FileListPanel, 1, wx.EXPAND)
   myself.vbox0.Add(myself.vbox, 5,
                    wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)


def set_song_info_panel(myself):
   myself.SongLabelPanel = wx.Panel(myself.SongInfoPanel, wx.ID_ANY,
                                    pos=(60, 6), size=(402, 40),
                                    style=wx.BORDER_RAISED)

   myself.SongDataLbl = wx.StaticText(myself.SongLabelPanel, wx.ID_ANY,
                                      '********** Song/Album Info **********',
                                      (40, 10))
   myself.SongDataLbl.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

   myself.AlbumImg = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
                                   (myself.p1titlepos, 55))

   myself.SongTitleVal = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                       'song name', (250, 120))
   #myself.SongTitleVal.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))

   myself.bylbl = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, 'by',
                                (250, 150))

   myself.SongArtistVal = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                        'artist name', (250, 180))
   #------------------------------------------------------------------------

   myself.NewTitleText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                       'New Title: ',
                                       (myself.p1titlepos, myself.p1vpos))
   myself.NewTitleBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                    pos=(myself.p1valuepos, myself.p1vpos),
                                    size=(240, 24))

   myself.NewTitleCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                   (myself.p1valuepos + 250, myself.p1vpos))

   myself.p1vpos += myself.p1vinc   # Each label/text pair is separated
                                    # vertically by the same fixed offset.

   myself.SubTitleText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                       'Subtitle: ',
                                       (myself.p1titlepos, myself.p1vpos))
   myself.SubTitleName = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
                                       (myself.p1valuepos, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.ArtistText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                     'Artist: ',
                                     (myself.p1titlepos, myself.p1vpos))
   #myself.ArtistName = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
   #                               (myself.p1valuepos,myself.p1vpos))
   myself.ArtistNameBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                      pos=(myself.p1valuepos, myself.p1vpos),
                                      size=(240, 24))
   myself.ArtistNameCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                     (myself.p1valuepos + 250, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.TrackText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                    'Track: ',
                                    (myself.p1titlepos, myself.p1vpos))
   myself.TrackNum = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
                                   (myself.p1valuepos, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.AlbumText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, 'Album: ',
                                    (myself.p1titlepos, myself.p1vpos))
   myself.AlbumNameBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                     pos=(myself.p1valuepos, myself.p1vpos),
                                     size=(240, 24))
   myself.AlbumNameCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                    (myself.p1valuepos + 250, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.RecDateText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                      'Record Year: ', (myself.p1titlepos,
                                      myself.p1vpos))
   myself.RecDateBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                   pos=(myself.p1valuepos, myself.p1vpos),
                                   size=(180, 24))

   #myself.RecDateNum = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
   #                               (myself.p1valuepos, myself.p1vpos))
   myself.RecDateCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                  (myself.p1valuepos + 250, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   #myself.RelTimeText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
   myself.RelDateText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                      'Release Date: ', (myself.p1titlepos,
                                      myself.p1vpos))
   #myself.RelTimeNum = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
   #                               (myself.p1valuepos, myself.p1vpos))
   myself.RelDateBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                   pos=(myself.p1valuepos, myself.p1vpos),
                                   size=(180, 24))
   myself.RelDateCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                  (myself.p1valuepos + 250, myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.ContentText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                      'Content Type:\n     (genre) ',
                                      (myself.p1titlepos, myself.p1vpos))
   myself.ContentTypeBox = wx.TextCtrl(parent=myself.SongInfoPanel, value="",
                                       pos=(myself.p1valuepos, myself.p1vpos),
                                       size=(240, 24))
   myself.ContentTypeCB = wx.CheckBox(myself.SongInfoPanel, wx.ID_ANY, 'Save',
                                      (myself.p1valuepos + 250,
                                       myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.EncodedByText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                        'Encoded By: ',
                                        (myself.p1titlepos,
                                        myself.p1vpos + 10))
   myself.EncodedByDesc = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
                                        (myself.p1valuepos,
                                        myself.p1vpos + 10))

   #myself.p1vpos += myself.p1vinc
   #myself.RadioStText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
   #                                   'Radio Station: ',
   #                                   (myself.p1titlepos,myself.p1vpos))
   #myself.RadioStDesc = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
   #                                   'desc ',
   #                                   (myself.p1valuepos,
   #                                   myself.p1vpos))

   myself.p1vpos += myself.p1vinc
   myself.CommentText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
                                      'Comment: ',
                                      (myself.p1titlepos, myself.p1vpos))
   myself.CommentDesc = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY, '',
                                      (myself.p1titlepos + 25,
                                      myself.p1vpos + 15))
   myself.CommentLink = wx.lib.hyperlink.HyperLinkCtrl(parent=myself.SongInfoPanel,
                                                       pos=(myself.p1titlepos + 10,
                                                       myself.p1vpos + 15))

   myself.SaveButton = wx.Button(myself.SongInfoPanel, wx.ID_ANY,
                                 label="Save Tags", pos=wx.Point(370, 480))
   myself.SaveButton.Bind(wx.EVT_BUTTON, myself.on_save)

   #myself.p1vpos += myself.p1vinc
   #myself.OtherTagsText = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
   #                                     'Other Tags: ',
   #                                     (myself.p1titlepos,myself.p1vpos))
   #myself.OtherTagsDesc = wx.StaticText(myself.SongInfoPanel, wx.ID_ANY,
   #                                     'desc ',
   #                                     (myself.p1valuepos,myself.p1vpos))


def set_file_info_panel(myself):
   myself.FileLabelPanel = wx.Panel(myself.FileInfoPanel, wx.ID_ANY,
                                    pos=(55, 6), size=(330, 40),
                                    style=wx.BORDER_RAISED)

   myself.FileDataLbl = wx.StaticText(myself.FileLabelPanel, wx.ID_ANY,
                                      '********** File Info **********',
                                      (40, 10))
   myself.FileDataLbl.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

   myself.FNameText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                    'File Name: ', (myself.p2titlepos,
                                    myself.p2vpos))
   myself.FNameBox = wx.TextCtrl(parent=myself.FileInfoPanel, value="",
                                 pos=(myself.p2valuepos, myself.p2vpos),
                                 size=(260, 24))

   myself.p2vpos += myself.p2vinc + 5  # Add 5 px to the vert offset
                                       # to allow for the previous text box

   myself.FSizeText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                    'File Size: ', (myself.p2titlepos,
                                    myself.p2vpos))
   myself.FSizeNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                   (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.FCreateText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                      'Created: ',
                                      (myself.p2titlepos, myself.p2vpos))
   myself.FCreateDate = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                      (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.FModText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                   'Last Mod: ',
                                   (myself.p2titlepos, myself.p2vpos))
   myself.FModDate = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                   (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.FAccText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                   'Last Access: ',
                                   (myself.p2titlepos, myself.p2vpos))
   myself.FAccDate = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                   (myself.p2valuepos, myself.p2vpos))

   #myself.p2vpos += myself.p2vinc
   #myself.FTypeText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
   #                          'File Type: ',
   #                           (myself.p2titlepos, myself.p2vpos))
   #myself.FTypeDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
   #                              (myself.p2valuepos,myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.LayerText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                    'Layer: ',
                                    (myself.p2titlepos, myself.p2vpos))
   myself.LayerDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                    (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.BitRateText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                      'Bit Rate: ',
                                      (myself.p2titlepos, myself.p2vpos))
   myself.BitRateNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                     (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.FreqText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                   'Frequency: ',
                                   (myself.p2titlepos, myself.p2vpos))
   myself.FreqNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                  (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.TrackLenText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                       'Track Length: ',
                                       (myself.p2titlepos, myself.p2vpos))
   myself.TrackLenNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                      (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.ModeText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, 'Mode: ',
                                   (myself.p2titlepos, myself.p2vpos))
   myself.ModeNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                  (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.PadText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                  'Padding: ',
                                  (myself.p2titlepos, myself.p2vpos))
   myself.PadDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                  (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.ProtectText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                      'Protected: ',
                                      (myself.p2titlepos, myself.p2vpos))
   myself.ProtectDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                      (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.SketchyText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                      'Sketchy: ',
                                      (myself.p2titlepos, myself.p2vpos))
   myself.SketchyDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                      (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.VerText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                  'MPEG Ver: ',
                                  (myself.p2titlepos, myself.p2vpos))
   myself.VerNum = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY, '',
                                 (myself.p2valuepos, myself.p2vpos))

   myself.p2vpos += myself.p2vinc
   myself.GetInfoStatusText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                            'Info Status: ',
                                            (myself.p1titlepos, myself.p2vpos))

   # *** Apparently underline doesn't work on the Linux platform!!! ***
   myfont = myself.GetInfoStatusText.GetFont()
   myfont.SetUnderlined(True)
   myself.GetInfoStatusText.SetFont(myfont)
   myself.GetInfoStatusDesc = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                            '-',
                                            (myself.p1titlepos + 10,
                                            myself.p2vpos + 20))

   #print "Last text pos: %d, %d" % (myself.p1titlepos, myself.p2vpos)
   if myself.LastFMok:
      PoweredByText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                    'Powered By: ',
                                    (25, 520))
      PoweredByText.SetForegroundColour((30, 144, 255))
      set_last_fm_image(myself)

   #*** DEBUG ***
   #myself.GetInfoStatusDesc.SetLabel("Col Cnt: " + str(mycnt))


def set_last_fm_image(myself):
   """ If using the Last.fm service, show their logo as attribution
   as requested by them.
   """

   if os.path.exists('lastfm_red_small.gif'):
      myself.LastFMImage = wx.StaticBitmap(myself.FileInfoPanel,
                                           bitmap=wx.EmptyBitmap(80, 25))
      myself.LastFMImage.SetPosition((120, 510))
      Img = wx.Image('lastfm_red_small.gif', wx.BITMAP_TYPE_GIF)
      myself.LastFMImage.SetBitmap(wx.BitmapFromImage(Img))
   else:
      LastfmLabelText = wx.StaticText(myself.FileInfoPanel, wx.ID_ANY,
                                      'Last.fm Web Services',
                                      (120, 520))
      LastfmLabelText.SetForegroundColour((30, 144, 255))

